/*
 * Copyright (C) 2013 Manuel Peinado
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package com.pla.lib.view.adapter;

import java.util.List;

import android.content.Context;
import android.database.Cursor;
import android.os.Bundle;
import android.support.v4.widget.SimpleCursorAdapter;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.BaseAdapter;
import android.widget.ListAdapter;

import com.pla.lib.view.PLA_AdapterView;
import com.pla.lib.view.PLA_AdapterView.OnItemClickListener;
import com.pla.lib.view.PLA_AdapterView.OnItemLongClickListener;
import com.pla.lib.view.listener.EnterMultiChoiceListener;
import com.pla.lib.view.listener.ItemClickInActionModePolicy;

/**
 */
public abstract class PLAMultiChoiceSimpleCursorAdapter extends SimpleCursorAdapter implements MultiChoiceAdapter {

	private PLAMultiChoiceAdapterHelper helper = new PLAMultiChoiceAdapterHelper(this);

	public PLAMultiChoiceSimpleCursorAdapter(Bundle savedInstanceState, Context context, int layout, Cursor cursor, String[] from, int[] to, int flags) {
		super(context, layout, cursor, from, to, flags);
		helper.restoreSelectionFromSavedInstanceState(savedInstanceState);
	}

	public void save(Bundle outState) {
		helper.save(outState);
	}

	public void setItemChecked(long itemId, boolean checked) {
		helper.setItemChecked(itemId, checked);
	}

	public List<Object> getCheckedItems() {
		return helper.getCheckedItems();
	}

	public int getCheckedItemCount() {
		return helper.getCheckedItemCount();
	}

	public boolean isChecked(Object itemId) {
		return helper.isChecked(itemId);
	}

	public void setItemChecked(Object position, boolean checked) {
		helper.setItemChecked(position, checked);
	}

	public void setItemClickInActionModePolicy(ItemClickInActionModePolicy policy) {
		helper.setItemClickInActionModePolicy(policy);
	}

	public ItemClickInActionModePolicy getItemClickInActionModePolicy() {
		return helper.getItemClickInActionModePolicy();
	}

	protected Context getContext() {
		return helper.getContext();
	}

	@Override
	public void cancelAllSeleted() {
		helper.cancelAllSeleted();
	}

	@Override
	public void registerMultiChoiceListener(EnterMultiChoiceListener listener) {
		helper.registerMultiChoiceListener(listener);
	}

	@Override
	public final View getView(int position, View convertView, ViewGroup parent) {
		View viewWithoutSelection = super.getView(position, convertView, parent);
		return helper.getView(position, viewWithoutSelection);
	}

	@Override
	public void removeCheckState(Object id) {
		helper.removeCheckState(id);
	}

	@Override
	public void setCheckedItems(List<? extends Object> items) {
		helper.setCheckedItems(items);
	}

	@Override
	public void setAdapterView(PLA_AdapterView<? super ListAdapter> adapterView) {
		helper.setAdapterView(adapterView);
	}

	@Override
	public void setAdapterView(AdapterView<? super BaseAdapter> adapterView) {
		// TODO Auto-generated method stub

	}

	@Override
	public void setOnItemClickListener(android.widget.AdapterView.OnItemClickListener listener) {
		// TODO Auto-generated method stub

	}

	@Override
	public void setOnItemLongClickListener(android.widget.AdapterView.OnItemLongClickListener listener) {
		// TODO Auto-generated method stub

	}

	@Override
	public void setPlaOnItemClickListener(OnItemClickListener listener) {
		helper.setOnItemClickListener(listener);
	}

	@Override
	public void setPlaOnItemLongClickListener(OnItemLongClickListener listener) {
		helper.setOnItemLongClickListener(listener);

	}

}